<?php
include("config.php");
if (!(isset($_SESSION["user"]) && $_SESSION["user"] != "") 
&& !(isset($_SESSION["auser"]) && $_SESSION["auser"] != "")) header('Location: index.php');
if (isset($adm_menu) && (!isset($_SESSION["auser"]) || $_SESSION["auser"] == "")) header('Location: index.php');

if (isset($_REQUEST['logfrom'])){
	$_SESSION['logfrom'] = $_REQUEST['logfrom'];
} else {
	if (!isset($_SESSION['logfrom'])) {
		$_SESSION['logfrom'] = date("Y.m.d");
	} 
}

if (isset($_REQUEST['logto'])){
	$_SESSION['logto'] = $_REQUEST['logto'];
} else {
	if (!isset($_SESSION['logto'])) {
		$_SESSION['logto'] = date("Y.m.d");
	} 
}
$f = convertdate($_SESSION['logfrom'],'iso','iso','.');
if ($f == NULL) $_SESSION['logfrom'] = date("Y.m.d");

$f = convertdate($_SESSION['logto'],'iso','iso','.');
if ($f == NULL) $_SESSION['logto'] = date("Y.m.d");

if (isset($_REQUEST['kodas'])){
	$kodas = $_REQUEST['kodas'];
} else {
	$kodas = "0";
}
if (isset($adm_menu)) {
	if (isset($_REQUEST['uid'])){
		$uid = $_REQUEST['uid'];
	} else {
		$uid = "";
	} 
} else {
	$uid = $_SESSION['user'];	
}



if ($kodas != "0") {
	$log_query = str_replace("<kodas>", " AND kodas='" . $kodas . "' ", $log_query);
} else {
	$log_query = str_replace("<kodas>", "", $log_query);
}

if (trim($uid) != "") {
	$log_query = str_replace("<vart_id>", " AND vart_id='" . addslashes_mssql($uid) . "' ", $log_query);
} else {
	$log_query = str_replace("<vart_id>", "", $log_query);
}

$data = " data between '".str_replace(".","-",$_SESSION['logfrom'])." 00:00:00' and '".str_replace(".","-",$_SESSION['logto'])." 23:59:59' ";
$log_query = str_replace("<data>", $data, $log_query);

$db_rdata = new DB($rdata_server_username,$rdata_server_pass,$rdata_server_db,$rdata_server,$rdata_driver);
		
include("header.php");
include("menu.php");


?>
<script type="text/javascript">
	$(document).ready(function(){	

		if (!$.browser.opera) {
    
			// select element styling
			$('select.select').each(function(){
				var title = $(this).attr('title');
				if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
				$(this)
					.css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
					.after('<span class="select">' + title + '</span>')
					.change(function(){
						val = $('option:selected',this).text();
						$(this).next().text(val);
						})
			});

		};
		
	});
</script>
  <script>
  $(function() {
    $( ".dt" ).datepicker({
      showOn: "button",
      buttonImage: "img/calendar.gif",
      buttonImageOnly: true,
	  dateFormat: "yy.mm.dd",
	  regional: "lt"
    });
  });
  </script>
<?php

	$f = "<form method=\"post\"><table cellspacing='0' cellpadding='5' class='params'>";
	
	$f .= "<tr><th>Pasirinkite periodą:</th></tr>";
	$f .= "<tr><td>Nuo&nbsp;&nbsp;&nbsp;<input class=\"dt\" type='text' name=\"logfrom\" value=\"" . $_SESSION['logfrom'] ."\"></td></tr>";
	$f .= "<tr><td>Iki&nbsp;&nbsp;&nbsp;<input class=\"dt\" type='text' name=\"logto\" value=\"" . $_SESSION['logto'] ."\"></td></tr>";
	
	if (isset($adm_menu)) { 
		$f .= "<tr><th>Kliento ID:</th></tr>";
		$f .= "<tr><td style='text-align:left;'><input  class=\"inp\" type='text' name=\"uid\" value=\"" . htmlspecialchars($uid) . "\"></td></tr>";
	} 	
	$f .= "<tr><th>Veiksmas:</th></tr>";
	$f .= "<tr><td style='text-align:left;'>";
        $f .= '<div>';
        $f .= '<select name="kodas" class="select" >';
		$f .= "<option value=\"0\"";  if ($kodas=="0") {$f .= 'selected="selected"';}$f .= ">Visi</option>";
		$inf = $db_rdata->returnList('SELECT [type_kodas],[type_pavad]  FROM [history_type] order by [type_kodas]');	
		foreach ($inf as $rec) {
			$f .= "<option value=\"".$rec['type_kodas']."\" "; if ($kodas=="".$rec['type_kodas']."") {$f .= 'selected="selected"';}$f .= ">".$rec['type_kodas'].". ".@iconv('windows-1257', 'UTF-8', htmlspecialchars($rec['type_pavad']))."</option>";
		}
		$f .= '</select>';
        $f .= '</div>		';
	$f .= "</td></tr>";
	$f .= "<tr><td ><input class='but bgfilter' type = \"submit\" value = \"Rodyti\"></td></tr>";
	$f .= "</table></form>";


$logs = $db_rdata->returnList($log_query);	
$d = "";

if (!empty($logs)) {

	$d .= '<table cellspacing="0" cellpadding="0" width="100%" border = "0">';
	$d .= '<tr><td align="center">';
	$d .= '<table cellspacing="0" cellpadding="5" class="innercont2">';
	if (!isset($oldstyle) || $oldstyle != "1") {
		$d .= '<tr><th>Data</th><th nowrap>Vartotojo nr.</th><th>Pavadinimas</th><th>Veiksmas</th><th>Tekstas</th><th>Vartotojo IP</th></tr>';
	}
	foreach ($logs as $log) {
		$d .= "<tr>";
		$d .= "<td nowrap>".$log["data"]."</td>";
		$d .= "<td>".$log["vart_id"]."</td>";
		$d .= "<td>".@iconv('windows-1257', 'UTF-8', $log["vart_pavad"])."</td>";
		$d .= "<td>".@iconv('windows-1257', 'UTF-8', htmlspecialchars($log["type_pavad"]))."</td>";
		$d .= "<td>".@iconv('windows-1257', 'UTF-8', $log["veiksmas"])."</td>";
		$d .= "<td>".$log["vart_ip"]."</td>";
		$d .= "</tr>\n";
	}

	$d .= '</table>';
	$d .= '</td>';
	$d .= '</tr></table>';

}



?>

<table class="innercont" cellspacing="0" cellpadding="10">
<tr><td class="leftcol">
<?php
if (isset($oldstyle) && $oldstyle == "1") {
?>
Istorija
<?php
echo $d;
} else {
echo $f;
}



?>
</td><td class="rightcol" rowspan="2">
<?php
if (isset($oldstyle) && $oldstyle == "1") {
	echo $f;
} else {
	echo $d;
}
?>
</td></tr>
<tr><td >

</td></tr>
</table>
<?php
include("footer.php");
?>